<template>
    <div class="contract-list-page change-identity-list">
        <Card>
            <ChangeForm
                :isSP="isSP"
                :formValidate="formValidate"
                :contractNo="contractNo"
                :dataDict="dataDict"
                :businessSource="businessSource"
                :loading="loading"
                @getList="getList"
            />
            <ChangeTable
                :spinShow="spinShow"
                :isSP="isSP"
                :formValidate="formValidate"
                :dataDict="dataDict"
                :contractTable="contractTable"
                :businessSource="businessSource"
                :loading="loading"
                @createRevoke="createRevoke"
                @getList="getList"
                @showDetail="showDetail"
                @closeSpin="closeSpin"
                @showSpin="showSpin"
            />
        </Card>
        <div v-if="detailModel">
            <Modal v-model="detailModel" :title="detailTitle" :width="1000" :closable="false"
                   :mask-closable="false">
                <ChangeDetailTable
                    :spinShow="spinShow"
                    :isSP="isSP"
                    :Obj="Obj"
                    :loading="loading"
                    :dataDict="dataDict"
                    @closeSpin="closeSpin"
                    @showSpin="showSpin"
                />
                <div slot="footer">
                    <Button size="small" @click="detailModel = false">返回</Button>
                </div>
            </Modal>
        </div>
        <Spin size="large" fix v-if="spinShow"></Spin>
    </div>
</template>
<script>
    // api
    import {mapGetters} from "vuex";
    import {
        getReceiptRecordList,
    } from "_p/basic/api/contract/revoke/revoke-collection";
    import {getDictDataList} from "_p/basic/assets/contract/js/utils";
    import {channelType, businessSource} from "_p/basic/api/contract/channel-type/channel-type";
    import ChangeForm from "./ChangeForm";
    import ChangeTable from "./ChangeTable";
    import ChangeDetailTable from "../ChangeDetailTable";

    export default {
        name: "revoke-collection-manage",
        components: {
            ChangeForm,
            ChangeTable,
            ChangeDetailTable,
        },
        props: {},
        data() {
            return {
                spinShow: false,
                contractBusiness: [
                    "collectionRevoke"],
                pageNo: 1,
                // 是否是合作商
                isSP: false,
                loading: false,
                contractNo: "",
                // 日期区间
                isDateErr: false,
                modelTitle: "",
                detailTitle: "",
                formValidate: {
                    applyNo: "", // 申请编号
                    contractNo: "", // 合同号
                    custName: "", // 客户名称
                    receiptStatus: "",//入账成功
                    pageNumber: 1,
                    pageSize: 50,
                    processStatus: null,
                    allCase: false,
                },
                contractTable: [] ,
                param: {},
                // TODO: 数据字典数据 ----- 案件类型r
                //  contractStatus 银行编码 receiptSourceType 付款方式 caseStatus 状态
                dicttArr: ["bankCode", "receiptSourceType", "receiptStatus", "feeType"],
                dataDict: {}, // 数据字典
                processStatusDict: [],
                contractStatusDict: [],
                processModeDict: [],
                modal: false,
                detailModel: false,
                logModel: false,
                caseNo: "",
                Obj: {
                    contractNo: "",
                    caseNo: "",
                    receiptId: ""
                },
            };
        },
        computed: {
            ...mapGetters({
                userInfo: "userInfo",
                roleType: "roles"
            }),
            getDataFn: () => findActivatedContractList
        },
        created() {
            this.getParams();
            this.isSP = channelType(this.$route.meta.params);
            this.businessSource = businessSource(this.roleType);
        },
        mounted() {
            console.group("初始数据：");
            console.log("contractNo:", this.contractNo);
            console.groupEnd();
        },
        activated() {
            this.init();
        },
        methods: {
            // 获取初始数据
            getParams() {
                const pageParams = this.afs.getPageParams(this);
                const {contractNo} = pageParams;
                this.contractNo = contractNo;
            },
            init() {
                this.getList(this.formValidate);
                this.getDictDataList();
            },
            getDictDataList() {
                getDictDataList(this.dicttArr).then(res => {
                    console.group("数据字典:");
                    console.log(this.dicttArr.join("  "));
                    console.log(JSON.parse(JSON.stringify(res)));
                    console.groupEnd();
                    this.dataDict = res;
                });
            },
            // 请求table数据
            getList(data) {
                if (!data) data = this.formValidate;
                data.contractNo = this.contractNo;
                this.loading = true;
                getReceiptRecordList(data)
                    .then(res => {
                        this.loading = false;
                        if (res.code === "0000" && res.data) {
                            this.contractTable = res.data.collectCancelVos;
                        } else {
                            this.$Message.error("Fail!");
                        }
                    })
                    .catch(e => {
                        console.error(e);
                    });
            },
            showSpin() {
                this.spinShow = true;
            },
            closeSpin() {
                this.spinShow = false;
            },
            createRevoke(params) {
                params.editFlag = false;
                params.receiptId = params.id;
                params.id = null;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/revoke-collection/revoke-collection-detial/index",
                    "收款撤销",
                    "ios-add",
                    params,
                    "revoke-collection-detial-" + params.id,
                    [],
                    true
                );
                this.back();
            },
            showDetail(params, type) {
                this.detailModel = true;
                this.Obj.contractNo = params.contractNo;
                this.Obj.receiptId = params.id;
            },
            back() {
                //关闭页面
                this.afs.closeTab(this);
            },
        }
    };
</script>
<style lang="less">
    @import "../../../../styles/common/form.less";

    .change-contact-list {
        .applyNo {
            cursor: pointer;
        }
    }

    .page {
        padding-top: 8px;
    }

    .text-center {
        text-align: center;
    }
</style>
